<%--
  Created by IntelliJ IDEA.
  User: 17400
  Date: 2023/6/13
  Time: 14:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>Event Details</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f3f3f3;
        }
        .container {
            max-width: 960px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .container h1 {
            color: #007BFF;
        }
        .comments {
            margin-top: 20px;
        }
        .comments .comment {
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }


        .comments .comment p {
            margin-bottom: 0; /* 让评论内容和时间更紧凑 */
        }
        .comments .comment p:last-child {
            margin-top: 8px; /* 在评论内容和时间之间添加一些间距 */
            color: #999;
            font-size: 0.8em;
        }

        form {
            margin-top: 20px;
            background-color: #f9f9f9;
            padding: 10px;
            border-radius: 5px;
        }
        textarea {
            width: 100%;
            min-height: 60px;
            resize: vertical;
        }
        button {
            background-color: #007BFF;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }

        .fixed-button {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .fixed-button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <%@ include file="header.jsp"%>
    <h1>${event.title}</h1>
    <p>搜索指数: ${event.searchIndex}</p>
    <p>创建时间: <fmt:formatDate value="${event.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></p>
    <p>${event.content}</p>

    <div class="comments">
        <h2>评论列表</h2>
        <c:forEach items="${comments}" var="item">
            <div class="comment">
                <p>${item.content}</p>
                <p>
                    <span>${item.user.nickname}</span>
                    <fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss" />
                </p>
            </div>
        </c:forEach>
    </div>

    <form action="addcommnet" method="post" id="commentForm">
        <h2>添加评论</h2>
        <textarea name="content" required></textarea>
        <input type="hidden" name="eventId" value="${event.id}">

        <c:if test="${user != null}">
            <input type="submit" value="提交">
        </c:if>
        <c:if test="${user == null}">
            <input type="button" title="登录后才能提交" value="提交" disabled>
        </c:if>
    </form>
</div>

<!-- Fixed Add Comment Button -->
<button class="fixed-button" onclick="scrollToCommentForm()">Add Comment</button>

<script>
    function scrollToCommentForm() {
        const formElement = document.getElementById('commentForm');
        formElement.scrollIntoView({behavior: "smooth"});
    }
</script>
</body>
</html>
